// https://leetcode.cn/problems/daily-temperatures/

class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        stack<int> s;
        int n = temperatures.size();
        vector<int> answers(n);
        for (int i = 0; i < n; ++i) {
            while (!s.empty() && temperatures[i] > temperatures[s.top()]) {
                int tmp = s.top();
                s.pop();
                answers[tmp] = i - tmp;
            }
            s.push(i);  
        }
        return answers;
    }
};